package webStudio7i.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.JOptionPane;

import webStudio7i.excepcion.DAOExcepcion;
import webStudio7i.negocio.SalaBll;

/**
 * Servlet implementation class ServletInsertarSala
 */
public class ServletInsertarSala extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ServletInsertarSala() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String Nombre = request.getParameter("txtNombre");
		int idLocal = Integer.parseInt( request.getParameter("cboLocal"));
		int Capacidad = Integer.parseInt( request.getParameter("txtCapacidad"));
		String Caracteristica =  request.getParameter("txtCaracteristica");
		//
		SalaBll Bll = new SalaBll();
		//
		try {
			if (!Bll.existeSalaEnLocal(Nombre, idLocal)){
				Bll.insertarSala(Nombre, Caracteristica, Capacidad, idLocal);				
				response.sendRedirect("busquedaSala.html");	
				
			}else{
				response.sendRedirect("insertarSala.jsp?SalaDuplicada=1&txtNombre="+Nombre+ "&cboLocal="+idLocal+"&txtCapacidad="+Capacidad+"&txtCaracteristica="+Caracteristica);
			}
			
		} catch (DAOExcepcion e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
